package com.ase.搜索插入位置;

/**
 * @author gyhstart
 * @create 2021/2/19 - 18:33
 **/
public class Solution {
    public static void main(String[] args) {
        int i = searchInsert(new int[]{1, 3, 5, 7, 9}, 10);
        System.out.println(i);
    }

    public static int searchInsert(int[] nums, int target){
        int left = 0, right = nums.length - 1;
        while(left <= right) {
            int mid = (left + right) / 2;
            if(nums[mid] == target) {
                return mid;
            } else if(nums[mid] < target) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        return left;
    }
}
